package com.hskn.hss.module.button.entity;

import com.hskn.hss.core.utils.uuid.IdUtils;
import com.hskn.hss.module.menu.entity.SysMenu;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;

/**
 * <p>
 *
 * </p>
 *
 * @author hskn
 * @since 2021-05-04
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class SysButton implements Serializable {

    private String id;

    /**
     * 菜单ID
     */
    private String menuid;

    /**
     * 按钮名称
     */
    private String name;

    /**
     * 标识
     */
    private String label;

    /**
     * 按钮类型
     */
    private String type;

    /**
     * 应用方法
     */
    private String action;

    /**
     * 状态 0 启用 1禁用
     */
    private String status;

    /**
     * 备注
     */
    private String remark;

    public SysButton() {
    }

    public SysButton(String id, String menuid, String name, String label, String type, String action, String status, String remark) {
        this.id = id;
        this.menuid = menuid;
        this.name = name;
        this.label = label;
        this.type = type;
        this.action = action;
        this.status = status;
        this.remark = remark;
    }

    public static SysButton builtSysButton(SysMenu sysMenu, String name, String label, String lastAction) {
        String id = IdUtils.randomUUID();
        /**
         * 菜单ID
         */
        String menuid = sysMenu.getId();
        String type = label;
        /**
         * 应用方法
         */
        String action = sysMenu.getAction() + "/" + lastAction;

        /**
         * 状态 0 启用 1禁用
         */
        String status = "0";
        /**
         * 备注
         */
        String remark = sysMenu.getParentName() + "->" + sysMenu.getName() + "->" + name;

        return new SysButton(id, menuid, name, label, type, action, status, remark);
    }
}
